package com.yf.fragmentlifecycle;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        int w = getWindowManager().getDefaultDisplay().getWidth();
		int h = getWindowManager().getDefaultDisplay().getHeight();
		FragmentManager manager = getFragmentManager();
		FragmentTransaction transaction = manager.beginTransaction();
		if (w > h) {
			// 横屏
//			transaction.replace(android.R.id.content, new SecondFragment());
			transaction.replace(R.id.container, new SecondFragment());
		} else {
			// 竖屏
//			transaction.replace(android.R.id.content, new FirstFragment());
			transaction.replace(R.id.container, new FirstFragment());
		}
		transaction.commit();
    }
    
}
